<extend name="Public:base" />
<block name="content">
        <div class="col-xs-12">
            <form class="form-horizontal"  id="validation-form" method="post" onsubmit="return check()" action='{:U("Coupon/editcoupon")}'>
                <div class="page-header">
                    <button id="save" class="btn btn-primary btn-sm radius5">保存</button>
                    <a href="{:U('Coupon/manage')}" class="btn btn-primary btn-sm radius5">返回</a>
                </div>
               <volist name="info" id="vo">
                <div class="form-group required">
                    <label class="col-sm-2 control-label">电子券名称：</label>
                    <div class="col-sm-10">
                        <input  class="form-control" type="text" placeholder="" name="volume_name"  value="{$vo.volume_name}"  style="width:200px;"/>
                    </div>
                </div>
                <div class="form-group required">
                    <label class="col-sm-2 control-label">面值：</label>
                    <div class="col-sm-10">
                        <input  class="form-control" type="text" placeholder="" name="total"  value="{$vo.total}" style="width:200px;display:inline;"/> 元
                    </div>
                </div>
                   <input type="hidden" name="volume_id" value="{:I('volume_id')}"/>
                <div class="form-group required">
                    <label class="col-sm-2 control-label">订单需满：</label>
                    <div class="col-sm-10">
                        <input  class="form-control" type="text" placeholder="" name="min"  value="{$vo.min}" style="width:200px;display:inline;"/> 元
                    </div>
                </div>
                <div class="form-group required">
                    <label class="col-sm-2 control-label">类型：</label>
                    <php>if($vo['type']=='1'){</php>
                    <label><input type="radio"  name="type" value="1" onclick="" checked="checked"/>代金券</label>&nbsp;&nbsp;&nbsp;&nbsp;
                    <label><input type="radio" name="type" value="2" onclick="" />现金券</label>
                    <php>}elseif($vo['type']=='2'){</php>
                    <label><input type="radio"  name="type" value="1" onclick="" />代金券</label>&nbsp;&nbsp;&nbsp;&nbsp;
                    <label><input type="radio" name="type" value="2" onclick="" checked="checked" />现金券</label>
                    <php>}</php>
                </div>
                <div class="form-group required">
                    <label class="col-sm-2 control-label">可用范围：</label>
                    <div class="col-sm-10">
                        <ul id="treeDemo" class="ztree"></ul>
                        <input type="hidden" id="tree" name="category" value=""/>
                    </div>
                </div>
                <div class="form-group required">
                    <label class="col-sm-2 control-label">状态：</label>
                    <php>if($vo['status']=='1'){</php>
                    <label><input type="radio"  name="status" value="1" onclick="" checked="checked"/>开启</label>&nbsp;&nbsp;&nbsp;&nbsp;
                    <label><input type="radio" name="status" value="0" onclick="" />关闭</label>
                    <php>}elseif($vo['status']=='0'){</php>
                    <label><input type="radio"  name="status" value="1" onclick="" />开启</label>&nbsp;&nbsp;&nbsp;&nbsp;
                    <label><input type="radio" name="status" value="0" onclick="" checked="checked"/>关闭</label>
                    <php>}</php>
                </div>
                <div class="form-group required">
                    <label class="col-sm-2 control-label">有效期：</label>
                    <label>开始时间：<input id="startDate" name="start_time" value="{$vo.start_time}" class="Wdate" type="text" onfocus="WdatePicker({dateFmt:'yyyy-M-d 00:00:00',minDate:'%y-%M-{%d'})"/></label>&nbsp;&nbsp;&nbsp;&nbsp;
                    <label>结束时间：<input id="endDate" name="end_time" value="{$vo.end_time}" class="Wdate" type="text" onfocus="WdatePicker({dateFmt:'yyyy-M-d 00:00:00',minDate:'%y-%M-{%d}'})"/></label>
                </div>
            </form>
        </div>
        </volist>
    </div>
</block>
<block name="javascript">
    <script src="__PUBLIC__/ztree/jquery.ztree.all-3.5.min.js"></script>
    <script src="__PUBLIC__/ztree/jquery.ztree.core-3.5.js"></script>
    <script src="__PUBLIC__/ztree/jquery.ztree.excheck-3.5.js"></script>
    <link  rel="stylesheet" type="text/css" href="__PUBLIC__/ztree/zTreeStyle.css" />
    <link  rel="stylesheet" type="text/css" href="__PUBLIC__/ztree/demo.css" />
    <script>

        $(function(){

        });
    </script>
    <script>

        var setting = {


            view: {
                expandSpeed: "fast",
//				fontCss: getFontCss                      //查询功能字体的变化
            },
            data: {
                simpleData: {                            //simple数据类型
                    enable: true,
                    pIdKey: "parentId"                   //父节点来自后台PID大小写易错，改了
                },
                keep: {
                    parent: true
                }
            },
            check: {
                enable: true,
                chkStyle: "checkbox",                      //添加checkbox多选功能
//				chkboxType: { "Y": "", "N": "" },         //父子节点独立，便于单独操作节点
                nocheckInherit: false
            },

            edit: {
                enable: true,
                showRemoveBtn: false,                      //不显示删除和重命名按钮
                showRenameBtn: false,

                drag: {
                    isCopy: true,
                    isMove: true,             //此时节点在普通情况下为拖动，ctrl+移动为复制

                    prev: false,               //只允许托到目标节点的后置节点，便于后台管理
                    next: true,
                    inner: false
                }
            },

        };

        var zNodes ={$menuList};
//        var authGroupId = {$data.id};

        //		alert(JSON.stringify(zNodes));
        //过滤节点的机制 直接return node表示不做任何过滤

        $(document).ready(function(){

            $('#save').click(function(e){
                var treeObj = $.fn.zTree.getZTreeObj("treeDemo");
                var nodes = treeObj.getCheckedNodes(true);

                var idList = "";
                $.each(nodes, function (index, info) {
                    if (idList != "") {
                        idList += ",";
                    }

                    idList += info.id;
                });

                $("#tree").val(idList);

            });


            function filter(node) {
                return node;
            }
            $.fn.zTree.init($("#treeDemo"), setting, zNodes);

            edit();


            //关闭弹出层
            $('#dialog').on('click','.ks-ext-close',function(){
                $("#dialog").css('display','none');
                $('.ks-ext-mask').css('display','none');
                return false;
            });

        });

        function check(){
            var volume_name = $('input[name=volume_name]').val();
            var total = $('input[name=total]').val();
            var min = $('input[name=min]').val();
            var start_time = $('input[name=start_time]').val();
            var end_time = $('input[name=end_time]').val();
            var category = $('input[name=category]').val();

            if($.trim(volume_name)==''){
                $.jbox.info('名称不能为空！','提示');
                return false;
            }
            if($.trim(total)==''){
                $.jbox.info('价格不能为空！','提示');
                return false;
            }
            if(isNaN($.trim(total))){
                $.jbox.info('请输入数字！','提示');
                return false;
            }
            if($.trim(total)==0){
                $.jbox.info('价格不能为零！','提示');
                return false;
            }
            if($.trim(min)==''){
                $.jbox.info('条件不能为空！','提示');
                return false;
            }
            if(isNaN($.trim(min))){
                $.jbox.info('请输入数字！','提示');
                return false;
            }
            if(category==''){
                $.jbox.info('范围不能为空！','提示');
                return false;
            }
            if($.trim(start_time)==''|| $.trim(end_time)==''){
                $.jbox.info('请设置有效期!','提示');
                return false;
            }

            $('#validation-form').ajaxSubmit(function(data){
                console.log(data);
                if(data=='1'){
                    $.jbox.tip("修改成功！", 'loading');
                    window.setTimeout(function () {window.location.href="{:U('Coupon/manage')}"; }, 500);
                }if(data=='2') {
                    $.jbox.info('没有任何修改！', '提示');
                }
            });

            return false;
        }

    </script>
</block>